﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bouyei.GeoCore.GeoParsers.GeoJson
{
    public class GeoJsonObject<T, G>
    {
        public string type { get; set; } = "FeatureCollection";

        public Feature<T, G>[] features { get; set; }

        public GeoJsonObject() { }

        public override string ToString()
        {
            return System.Text.Json.JsonSerializer.Serialize(this);
        }

        public void FromGeoJson(string geoJson)
        {
            var rt = System.Text.Json.JsonSerializer.Deserialize<GeoJsonObject<T, G>>(geoJson);
            this.type = rt.type;
            this.features = rt.features;
        }
    }

    public class Feature<T, G>
    {
        public string type { get; set; } = "Feature";

        public T properties { get; set; }

        public GeoGeometry<G> geometry { get; set; }
    }

    public class GeoGeometry<G>
    {
        public string type { get; set; } = "Point";

        public G coordinates { get; set; }

        public GeoGeometry(string type)
        {
            this.type = type;
            coordinates = Activator.CreateInstance<G>();
        }

        public GeoGeometry()
        {
            if (coordinates is PointMArray)
                this.type = "MultiPoint";
            if (coordinates is LineArray)
                this.type = "LineString";
            else if (coordinates is LineMArray)
                this.type = "MultiLineString";
            else if (coordinates is PolygonArray)
                this.type = "Polygon";
            else if (coordinates is PolygonMArray)
                this.type = "MultiPolygon";

            coordinates = Activator.CreateInstance<G>();
        }
    }
}
